package test;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;

//飞机
public class Plane {

	//1
	int x;
	int y;
	int w;
	int h;

	public int score=0; //分数
	public int hp = 9999; //生命值
	public int count = 2;
	public int flag=1;   //初始状态 1，loading界面  0游戏界面
	boolean left=false,up=false,right=false,down=false;//键盘控键开关
	boolean destroy =false;//飞机的销毁状态
	
	int planeCount=0;//计数器
	int index=0;
	BufferedImage [] imgs=new BufferedImage[6];

	int bulletCate = 1;  //子弹种类 默认1  2 双弹
	
	//2初始化
	public Plane(){
		w=60;
		h=76;
		x=480/2-w/2;
		y=450;
		for (int i = 0; i < imgs.length; i++) {
			try {
				imgs[i]=ImageIO.read(getClass().getResource("/plane0"+(i+1)+".png"));
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	//3 绘制
	public void paint(Graphics g){
		if(hp>0) {

			g.drawImage(imgs[index], x, y, null);
			planeCount++;
			if (planeCount % 2 == 0) {
				index++;
			}
			if (index >= 2) {//重置数组下标
				index = 0;
			}
		}
		else {
			hp = 0;
			if(count<=(imgs.length-1)) {
				g.drawImage(imgs[count], x, y, null); //被击中爆炸效果
				count++;
			}
			else {
				count = 1;
				g.drawImage(null, x, y, null);  //爆炸效果完成 销毁,游戏结束
				flag = 1; //飞机销毁标志
			}
		}
	}
	
	//移动
	public void move(){
		if(destroy){//如过已销毁状态  结束此方法
			return;
		}
		if(left)
			x-=10;
		if(right)
			x+=10;
		if(up)
			y-=10;
		if(down)
			y+=10;
		if(x<0){//限制左边出界
			x=0;
		}
		if(x>480-w){//限制右边出界
			x=480-w;
		}
		if(y<0){//限制上边边框出界
			y=0;
		}
		if(y>652-h){//限制下面边框出界
			y=652-h;
		}
		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
